`
https://leetcode.cn/problems/reverse-only-letters/
`

/**
 * @param {string} s
 * @return {string}
 */
var reverseOnlyLetters = function (s) {
  s = s.split('')
  let left = 0, right = s.length - 1
  while (left < right) {
    while (left < right && !isAlpha.test(s[left])) left++
    while (left < right && !isAlpha.test(s[right])) right--
      ;[s[left], s[right]] = [s[right], s[left]]
    left++
    right--
  }
  return s.join('')
};

const isAlpha = /[a-zA-Z]/